package com.sky.mapper;

import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    //插入所有菜品
    void insertSetmealDishBunch(Long setmealId, List<SetmealDish> setmealDish);

    //根据id查询所有菜品
    @Select("select * from setmeal_dish where setmeal_id=#{id}")
    List<SetmealDish> selectDishesBySetmealId(Long id);

    //查询是否有菜品未启售 如果为空则都启售 如果为0则有未启售菜品
    @Select("select 1 from (select * from dish where dish.status=0 order by status) d where d.id in (select sd.dish_id from setmeal_dish sd where setmeal_id=#{id})limit 1")
    Integer isAllOnsell(Integer id);

    //删除套餐下所有菜品
    @Delete("delete from setmeal_dish where setmeal_id=#{id}")
    void deleteSetmealDishById(Long id);

    //批量删除菜品
    void deleteSetmealDishByIds(List<Long> ids);

    //查询菜品是否与套餐关联
    Integer isDishesLinkedWithSetmeal(List<Long> ids);
}
